package org.tio.sitexxx.service.init;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tio.utils.Uuid;
import org.tio.utils.jfinal.P;

/**
 * @author tanyaowu
 * 2016年8月7日 下午1:49:05
 */
public class PropInit {
	private static Logger log = LoggerFactory.getLogger(PropInit.class);

	@SuppressWarnings("unused")
	private static boolean inited = false;

	/**
	 * 配置信息加载
	 */
	public static void init() {
		System.setProperty("org.freemarker.loggerLibrary", "SLF4J");
		synchronized (log) {
			P.use("app.properties");
			P.append("app-env.properties");
			P.append("app-host.properties");

			//设置一下，用于生成高性能的uuid，这里耦合度略高，后面再优化一下
			Integer workerid = P.getInt("uuid.workerid");
			Integer datacenter = P.getInt("uuid.datacenter");

			if (workerid != null) {
				Uuid.setWorkid(workerid);
			}
			if (datacenter != null) {
				Uuid.setDatacenterid(datacenter);
			}
			inited = true;
		}
	}

}
